
#ifndef STEPMOTOR_H
#define STEPMOTOR_H


typedef struct stepmotor_tag{
	int pos;
	unsigned char enable;
	unsigned char output;
} stepmotor;


void stepmotor_init(stepmotor* motor)
{
	motor->output = 0;
	motor->enable = 0;
	motor->pos = 0;
}


void stepmotor_rotate(stepmotor* motor, int direction)
{
	if(direction > 0){
		motor->pos++;
	}
	else{
		motor->pos--;
	}
	if(motor->enable){
		if((motor->pos & 3) == 0){
			motor->output = 0x0A; //0b00001010;
		}
		else if((motor->pos & 3) == 1){
			motor->output = 0x09; //0b00001001;
		}
		else if((motor->pos & 3) == 2){
			motor->output = 0x05; //0b00000101;
		}
		else if((motor->pos & 3) == 3){
			motor->output = 0x06; //0b00000110;
		}
	}
}


#endif
